//
//  NavigationController.swift
//  weibo
//
//  Created by Fly on 2017/12/11.
//  Copyright © 2017年 Fly. All rights reserved.
//

import UIKit

class NavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        navigationBar.isHidden = true
        
    }

    // MARK: 重写navigationController的push方法，隐藏tabbar
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        // 只有非根视图控制器才需要在跳转的时候隐藏tabbar
        if childViewControllers.count > 0 {
            
            viewController.hidesBottomBarWhenPushed = true
            
            // 判断控制器类型
            if let vc = viewController as? BaseViewController {
                
                var title = "返回"
                
                // 判断控制器级数
                if childViewControllers.count == 1 {
                    
                    title = childViewControllers.first?.title ?? "返回"
                    
                }
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, isBackBtn: true, target: self, action: #selector(back))
                
            }
    
        }
        
        super.pushViewController(viewController, animated: true)
        
    }
    
    @objc private func back() {
    
        popViewController(animated: true)
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
}
